package view.GUI.otherView;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;

import org.controlsfx.dialog.Dialog;
import org.controlsfx.dialog.Dialogs;

import enums.GUIText;
import view.GUI.mainView.MainView;


public class PWDialog extends Dialog{

	private MainView owner;
	
	public PWDialog(MainView owner, String title) {
		super(owner.getPrimaryStage(), title);
		this.owner = owner;
		showDialog();
	}

	 final PasswordField txPassword = new PasswordField();
	   
	 private void showDialog() {
	     Dialog dlg = new Dialog(null, GUIText.PASSWORD.toString());
	       
	     final GridPane content = new GridPane();
	     content.setHgap(10);
	     content.setVgap(10);

	     content.add(new Label(GUIText.PASSWORD.toString()), 0, 1);
	     content.add(txPassword, 1, 1);
	     GridPane.setHgrow(txPassword, Priority.ALWAYS);
	     
	     Button btnOk = new Button(GUIText.OK.toString());
	     btnOk.setOnAction(new EventHandler<ActionEvent>(){

			@Override
			public void handle(ActionEvent arg0) {
				try{
					owner.createInvoice(txPassword.getText());
					dlg.hide();
				} catch(IllegalArgumentException e){
					Dialogs.create()
							.message(e.getMessage())
							.showError();
				}

			}    	 
	     });
	     
	     content.add(btnOk, 1, 2);
	       
	     // create the dialog with a custom graphic and the gridpane above as the
	     // main content region
	     dlg.setResizable(false);
	     dlg.setIconifiable(false);
//	     dlg.setGraphic(new ImageView(HelloDialog.class.getResource("login.png").toString()));
	     dlg.setContent(content);
	       

	     dlg.show();
	 }
}
